package flc.ast.adapter;

import android.text.format.DateUtils;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;

import java.text.SimpleDateFormat;
import java.util.TimeZone;

import flc.ast.R;
import flc.ast.bean.AppInformation;
import flc.ast.databinding.ItemRvScreenAppUseStyleBinding;
import stark.common.basic.adapter.BaseDBRVAdapter;

public class ScreenAppUseAdapter extends BaseDBRVAdapter<AppInformation, ItemRvScreenAppUseStyleBinding> {

    private long totalTime;

    public void setTotalTime(long totalTime) {
        this.totalTime = totalTime;
    }

    public ScreenAppUseAdapter() {
        super(R.layout.item_rv_screen_app_use_style, 0);
    }

    @Override
    protected void convert(@NonNull BaseDataBindingHolder<ItemRvScreenAppUseStyleBinding> holder, AppInformation item) {
        super.convert(holder, item);
        ItemRvScreenAppUseStyleBinding binding = holder.getDataBinding();
        binding.ivIcon.setImageDrawable(item.getIcon());
        binding.tvName.setText(AppUtils.getAppName(item.getPackageName()));
        SimpleDateFormat sdf = new SimpleDateFormat("HH小时mm分钟");
        sdf.setTimeZone(TimeZone.getTimeZone("GMT+0"));
        binding.tvDuration.setText(TimeUtils.millis2String(item.getUsedTimebyDay(), sdf));
        int progress = Math.round((item.getUsedTimebyDay() * 100f / totalTime));
        binding.pbProgress.setProgress(progress);
//        long timeUsed = item.getTotalTimeInForeground(); // 获取应用前台使用时长，单位是毫秒
//
//        // 计算小时、分钟、秒
//        long hours = timeUsed / (1000 * 60 * 60); // 转换为小时
//        long minutes = (timeUsed % (1000 * 60 * 60)) / (1000 * 60); // 计算剩余的分钟
//        long seconds = (timeUsed % (1000 * 60)) / 1000; // 计算剩余的秒
//
//        // 格式化成时分秒形式
//        String timeUsedFormatted = String.format("%02d:%02d:%02d", hours, minutes, seconds);
//
//        // 显示时分秒形式
//        binding.tvDuration.setText(timeUsedFormatted);
//        long lastTimeUsed  = item.getLastTimeUsed();
//        // 获取最后使用时间
//        binding.tvBefore.setText(TimeUtils.millis2String(lastTimeUsed, "yyyy-MM-dd HH:mm") + "使用过");

    }
}
